using System;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Xml.Serialization;

namespace Application.MainModule.UserManagement
{
    public class UserDTO
    {
        public int CustomerId { get; set; }
        [StringLength(15), Required]
        public string CustomerName { get; set; }
        [Required]
        public string AuthorizationId { get; set; }
        public string CustomerEmail { get; set; }
        public string CustomerPassword { get; set; }
        public bool IsActive { get; set; }
        public bool IsRegister { get; set; }

        public override string ToString()
        {
            var serializer = new XmlSerializer(typeof(UserDTO));
            using (var stream = new StringWriter())
            {
                serializer.Serialize(stream, this);
                return stream.ToString();
            }
        }

        public static UserDTO FromString(string userContextData)
        {
            var serializer = new XmlSerializer(typeof(UserDTO));
            using (var stream = new StringReader(userContextData))
            {
                return serializer.Deserialize(stream) as UserDTO;
            }
        }
    }
}